package main

import (
    "bufio"
    "fmt"
    "os"
)

var Input = bufio.NewReader( os.Stdin )

var hall = Room{
    description: "You are in a big hall",
    objects: map[string]Object{
        "candle": Object{
            name: "candle",
            description: "a candle",
            examine: DoesNothing,
            use: DoesNothing,
            use_on: nil,
        },
    },
    exits: make(map[direction]*Room),
}

var game = Game{
    rooms: []Room{ hall },
    player_location: nil,
    player_inventory: make(map[string]Object),
}

func main() {
    game.player_location = &game.rooms[0]
    for {
        fmt.Println("========================================")
        game.player_location.describe()

        if input, err := Input.ReadString( '\n' ); err == nil {
            action, ok := parse( input )

            if !ok {
                fmt.Println( "I did not understand that!" )
                continue
            }

            switch action.verb {
            case LOOK:
                if obj, ok := game.player_location.objects[action.object]; ok {
                    fmt.Println( "You look at the", action.object )
                    obj.describe()
                } else if obj, ok := game.player_inventory[action.object]; ok {
                    fmt.Println( "You look at the", action.object, "in your backpack" )
                    obj.describe()
                } else {
                    fmt.Println( action.object )
                    fmt.Println( "I know of no such thing!" )
                }
            case USE:
                if obj, ok := game.player_inventory[action.object]; ok {
                    if action.subject != nil {
                    } else {
                        obj.use.invoke( game )
                    }
                } else {
                }
            case PICK:
                if obj, ok := game.player_location.objects[action.object]; ok {
                    fmt.Println( "You pick up the", action.object )
                    delete( game.player_location.objects, "candle" )
                    game.player_inventory[action.object] = obj
                } else {
                    fmt.Println( "There is no such thing as a", action.object )
                }
            }
        } else {
            fmt.Println( "Fuckup!" )
        }
    }
}
